/**
 * Unicorn Admin Template
 * Diablo9983 -> diablo9983@gmail.com
**/
$(document).ready(function(){
	/*if($(this).find('colorpicker').exist()) {
		
	}
	$('body').find('.Mandatory').length;*/
	if($('.colorpicker').length){
		$('.colorpicker').colorpicker();
	}
	if($('.usertokenfield').length){
		$('.usertokenfield').tokenfield();
	}
	if($('.switch').length){
		$('.switch').bootstrapSwitch();
	}
	if($('.check').length){
		$('.check').iCheck({
			checkboxClass: 'icheckbox_square-blue',
			radioClass: 'iradio_square-blue',
			increaseArea: '20%' // optional
		});
	}
	if($('.datepicker').length){
		$('body').on('focus',".datepicker", function(){
			$(this).datepicker();
		});
		//$('.datepicker').datepicker();
	}
	if($('.selectpicker').length){
		$('.selectpicker').selectpicker();
	}
	
	

	//$('select').select2();
	$.validator.addMethod("valueNotEquals", function(value, element, arg){
	  return arg != value;
	 }, "Please Select an Item");
	 
	 $.validator.addMethod("noSpace", function(value, element) { 
    return value.indexOf(" ") < 0 && value != ""; 
  }, "Space are not allowed");

	 //password validation
	 // Form Validation
    $("#registration_form").validate({
		rules:{
			firstname:{
				required:true
			},
			lastname:{
				required: true,
				
			},
			email:{
				required: true,
				email:true,
			},
			password:{
				required: true,
				minlength:6,
				maxlength:20
			},
			cpassword: {
                required:true,
				equalTo:"#password"
			},
			terms:{
				required:true,
			},
		},
		errorClass: "error",
		errorElement: "label",
		errorPlacement: function (error, element) {
			//alert(element.attr("name"));
			 switch (element.attr("name")) {
				case 'terms':
					error.insertAfter(element.parents('.form-group'));
					error.css('margin-left', '177px');
					break;
				default:
					error.insertAfter(element);
					
					break;
			}
		},
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.form-group').addClass('errorform');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.form-group').removeClass('errorform');
			$(element).parents('.form-group').addClass('success');
		}
	});
	 $("#forgot-form").validate({
		rules:{
			pemail:{
				required: true,
				email:true,
			},	
		},
		errorClass: "error",
		errorElement: "label",
		errorPlacement: function (error, element) {
        error.insertAfter(element);
		},
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.control-group').addClass('error');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.control-group').removeClass('error');
			$(element).parents('.control-group').addClass('success');
		}
	});
	
	$("#change_password").validate({
		rules:{
			password:{
				required:true
			},
			cpassword: {
                required:true,
				equalTo:"#npassword"
			},
		},
		errorClass: "error",
		errorElement: "label",
		errorPlacement: function (error, element) {
        error.insertAfter(element);
		},
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.control-group').addClass('error');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.control-group').removeClass('error');
			$(element).parents('.control-group').addClass('success');
		}
	});
	
	$("#general_setting_form").validate({
		rules:{
			email:{
				
				email:true,
			},
			password:{
				
				minlength:6,
				maxlength:20
			},
			cpassword: {
                
				equalTo:"#password"
			},
		},
		errorClass: "error",
		errorElement: "label",
		errorPlacement: function (error, element) {
        error.insertAfter(element);
		},
		highlight:function(element, errorClass, validClass) {
			$(element).parents('.control-group').addClass('error');
		},
		unhighlight: function(element, errorClass, validClass) {
			$(element).parents('.control-group').removeClass('error');
			$(element).parents('.control-group').addClass('success');
		}
	});
	
});
